import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.concurrent.*;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

class   Student{
    private  int a;
    public int b;
    public int c;
    private  void fun1(){
        System.out.println("fun1");
    }
    public void fun2(){
        System.out.println("fun2");
    }
}
public class Test {
    public static void main(String[] args) {
        ThreadLocal<Object> threadLocal = new ThreadLocal<>();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10,10,1, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
            threadLocal.set(new Object());
                System.out.println(threadLocal.get());
                threadLocal.remove();
            }
        };
        Thread thread = new Thread(()->{
            System.out.println("111");
        });
        thread.start();
        ReentrantLock reentrantLock = new ReentrantLock();
        Condition condition = reentrantLock.newCondition();
        condition.signalAll();



    }
    public static void main3(String[] args) throws InterruptedException {
        ThreadLocal<String> local = ThreadLocal.withInitial(()->"1111");

        local.set("11222");
        System.out.println(local.get());

        Thread thread = new Thread(()->{
           String name =  local.get();
            System.out.println("线程1："+name);
            local.set("wangwu");
            String name1 = local.get();
            System.out.println("线程1："+name1);
        });

        Thread thread1 = new Thread(){
            @Override
            public void run() {
                String name = local.get();
                System.out.println("线程2："+name);
                local.set("xxx");
                System.out.println("线程2："+local.get());

            }
        };
        thread.start();
        thread1.start();
        thread.join();
        thread1.join();


    }

    public static void main2(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException {
        Class<?> student = Class.forName("Student");
         Student student1 = (Student) student.newInstance();
         student1.fun2();
       Field field = student.getField("b");
       field.setAccessible(true);
        System.out.println(field);

       Field[] field1 = student.getFields();
        System.out.println(Arrays.toString(field1));

        Method method = student.getMethod("fun2");
        System.out.println(method);
        Field[] fields = student.getDeclaredFields();
        System.out.println(Arrays.toString(fields));


    }


    public static int getFun(int n){
        int sum = 0;
        while(n>0){
            sum+=n%10;
            n/=10;
        }
        return sum;
    }
    public static int[]  sort(int[] arr){
        for(int i =0;i<arr.length-1;i++){
            for(int j = 0;j<arr.length-1-i;j++){
                if(getFun(arr[j+1])<getFun(arr[j])){
                    int tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
        return arr;
    }

        public static void main1(String[] args) {
            Scanner in = new Scanner(System.in);

            ArrayList<Integer> list = new ArrayList<>();
            LinkedList<Integer> list1  = new LinkedList<>();
            // 注意 hasNext 和 hasNextLine 的区别
            while (in.hasNextInt()) { // 注意 while 处理多个 case
                int a = in.nextInt();
                int[] arr = new int[a];
                int[] acc = new int[a];
            for(int i = 0;i<arr.length;i++){
              arr[i] =in.nextInt();
            }
            for(int i = 0;i<arr.length;i++){
                acc[i] = getFun(arr[i]);
            }
             acc = sort(arr);
                System.out.println(Arrays.toString(acc));

            }
        }

}
